#!/usr/bin/python
#copy netconfig objects from one Mu to the other
import MuConnection, MuNetworkConfiguration, time, sys, getopt

USERNAME = 'admin'
PASSWORD = ''
PASSWORD2 = ''
MU = ''
MU2 = ''
COPY = 'hosts'

#get the username and password
args = sys.argv[0:]
try:
    options, remainder = getopt.getopt(sys.argv[1:], "p:P:i:I:c:", ["passwod=", "password2=","ipaddress=","ipaddress2=","copy="])
except getopt.GetoptError, err:
    # print help information and exit:
    print str(err) # will print something like "option -a not recognized"
    #usage()
    sys.exit(2)
for o, p in options:
    if o in ("-p","--pwd1"):
     	PASSWORD = p
    elif o in ("-P", "--pwd2"):
     	PASSWORD2 = p
    elif o in ("-i", "--mu1"):
        MU = p
    elif o in ("-I", "--mu2"):
        MU2 = p
    elif o in ("-c", "--coppy"):
        COPY = p


myMuConnection = MuConnection.MuConnection("https://"+MU,USERNAME,PASSWORD)



myConfig = MuNetworkConfiguration.MuNetworkConfig(myMuConnection)
myConfig.VERBOSE = True
myMuConnection.VERBOSE - True

if COPY=='hosts':
	hostList = myConfig.getHostList()
	myMuConnection2 = MuConnection.MuConnection("https://"+MU2,USERNAME,PASSWORD2)
	myConfig2 = MuNetworkConfiguration.MuNetworkConfig(myMuConnection2)
	myConfig2.VERBOSE = True
	myMuConnection2.VERBOSE - True
	for host in hostList:
		myHost = MuNetworkConfiguration.host(host)
		print "adding host: "+myHost.getName()
		myConfig2.addHost(myHost)
else:
	print "UNKNOWN OPERATION: "+COPY
